//
//  CategoryModel.swift
//  FM
//
//  Created by x on 2017/8/23.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class CategoryModel: NSObject {

    /// id
    var id:String?
    
    /// <#Description#>
    var sort:String?
    
    /// 显示图片
    var cover:String? {
        didSet {
            categoryImageURL = URL(string: cover!)
        }
    }
    
    /// 标题
    var name:String?
    
    /// ????
    var flag:String?
    
    /// 保存按钮的图片URL
    var categoryImageURL:URL?
    
    /// 快速返回一个数据模型
    ///
    /// - Parameter data: <#data description#>
    /// - Returns: <#return value description#>
    class func analysisData(data:AnyObject?) ->[CategoryModel] {
        
        let category = data?["category"] as![[String:AnyObject]]
        var categoryModels:[CategoryModel] = [CategoryModel]()
        for dic in category {
            let model = CategoryModel(dic: dic)
            categoryModels.append(model)
        }
        
        return categoryModels
    }
    
    init(dic:[String: AnyObject]) {
        super.init()
        setValuesForKeys(dic)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        print("key=====",key)
    }
    
    //重写descripation方法
    let tt = ["id","sort","name","cover","flag"]
    override var description: String {
        let dic = dictionaryWithValues(forKeys: tt)
        
        return "\(dic)"
    }

}
